package com.run2code.idea.plugin.codegenerate.biz.db.bizdata;

import com.google.common.base.CaseFormat;
import org.apache.commons.lang3.StringUtils;

import java.util.Set;
/**
 * 基础业务模型
 * 关注公众号【奔跑的码畜】，一起进步不迷路
 *
 * @author 第七人格
 * @date 2023/10/30
 */
public abstract class Base {

    /**
     * 类型
     */
    private int type;
    /**
     * 描述
     */
    private String comment;
    /**
     * 名字
     */
    private String name;

    public Base(String comment, String name) {
        this.comment = comment;
        this.name = name;
    }

    public String getPackage() {
        String str = StringUtils.substringAfterLast(name, "java/");
        if (!"".equals(str)) {
            str = str.substring(0, str.lastIndexOf(getSimpleName()) - 1);
        }
        return str.replaceAll("/", ".");
    }

    /**
     * 子类实现这个接口，返回一个Set，里面是导入的包名
     *
     * @return {@link Set}<{@link String}>
     */
    public abstract Set<String> getImports();

    public String getSimpleName() {
        return name.lastIndexOf("/") == -1 ? name : StringUtils.substringAfterLast(name, "/");
    }

    public String getVarName() {
        return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, getSimpleName());
    }

    public String getName() {
        return name;
    }

    public String getMapperName() {
        String str = StringUtils.substringAfterLast(name, "java/");
        return str.replaceAll("/", ".");
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public void setName(String name) {
        this.name = name;
    }
}
